package com.dsteiner.widgets.client.domain;

import com.dsteiner.widgets.client.ObjectUtil;


public class Sort extends BaseObject{

	private String field;
	private boolean asc;

	public Sort() {
	}
	
	public Sort(String field, boolean asc) {
		this.field = field;
		this.asc = asc;
	}
	
	public Sort(String sort) {
		this(sort.split(" ")[0], "asc".equals(sort.split(" ")[1]));
	}
	
	public String getField() {
		return field;
	}
	public boolean isAsc() {
		return asc;
	}

	@Override
	public String toString() {
		return field + (asc ? " asc" : " desc");
	}
	
	public boolean equals(Object obj) {
		if (obj == null)
			return false;
		if (!(obj instanceof Sort))
			return false;
		Sort other = (Sort) obj;
		return ObjectUtil.equals(other.field, field) && ObjectUtil.equals(other.asc, asc);
	}
}
